package com.lcm.test.designpatterntest.Singleton;

import lombok.extern.slf4j.Slf4j;


/**
 * @description:
 * @author: lcm
 * @create: 2020-03-11 15:40
 **/
@Slf4j
public class InnerClassSingleton {

    public int value=1;

    private static class Inner{
        private static InnerClassSingleton singleton;
        static {
            singleton=new InnerClassSingleton();
            log.info("内部类单例初始化成功");
        }
    }

    public static InnerClassSingleton getSingleton(){
        return Inner.singleton;
    }

    public static void main(String[] args){
        System.out.println("懒加载单例，只有再真正调用的时候，才会初始化！");
        System.out.println(InnerClassSingleton.getSingleton().value);
    }

}
